package com.xiaoran.RMQ_1.test1;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Produce_one {
    public static final  String QUEUE_NAME="mirrior_hello";
    public static final  String  IP="192.168.171.128";
    public static void main(String args[]) throws IOException, TimeoutException {
        //1.创建连接工厂
        ConnectionFactory connectionFactory=new ConnectionFactory();
        //2.工厂IP连接RabbitMQ的队列
        connectionFactory.setHost(IP);
        //3.设置用户名
        connectionFactory.setUsername("admin");
        //4.设置密码
        connectionFactory.setPassword("123");
        //5。创建连接
        Connection connection=connectionFactory.newConnection();
        //6。创建信道
        Channel channel=connection.createChannel();
        //7.生成队列
        channel.queueDeclare(QUEUE_NAME,true,false,false,null);
        //8.发送消息
        String message="hello word";
        channel.basicPublish("",QUEUE_NAME,null,message.getBytes());
        //9.消息发送成功执行
        System.out.println("消息发送成功");
    }
}
